package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallMemberOrderMapper;
import org.linlinjava.litemall.db.domain.LitemallMemberOrder;
import org.linlinjava.litemall.db.domain.LitemallMemberOrderExample;
import org.linlinjava.litemall.db.util.PayStatusConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Administrator
 */
@Service
public class LitemallMemberOrderService {
    @Resource
    private LitemallMemberOrderMapper memberOrderMapper;

    public LitemallMemberOrder findById(Integer id) {
        LitemallMemberOrderExample example = new LitemallMemberOrderExample();
        example.or().andIdEqualTo(id).andDeletedEqualTo(false);
        return memberOrderMapper.selectOneByExample(example);
    }

    public void delete(Integer memberOrderId) {
        memberOrderMapper.logicalDeleteByPrimaryKey(memberOrderId);
    }

    public LitemallMemberOrder findDepositByUserId(Integer userId) {
        LitemallMemberOrderExample example = new LitemallMemberOrderExample();
        example.or().andUserIdEqualTo(userId).andPayStatusBetween(PayStatusConstant.HAS_PAID, PayStatusConstant.UN_REFUNDED).andTypeEqualTo(2).andDeletedEqualTo(false);
        return memberOrderMapper.selectOneByExample(example);
    }
}
